﻿using mozhi.smarterp.Finance.Accounts.Events;
using mozhi.smarterp.Finance.Accounts.Repository;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;

namespace mozhi.smarterp.Finance.Accounts.EventHandlers
{
    public class AccountingStandardChangeHandler : IDistributedEventHandler<AccountingStandardChangeEvent>,
          ITransientDependency
    {
        private ICurrentTenant _currentTenant;
        private IAccountRepository _accountRepository;
        public AccountingStandardChangeHandler(ICurrentTenant currentTenant , IAccountRepository accountRepository) 
        {
            _currentTenant = currentTenant;
            _accountRepository = accountRepository;
        }

        public async Task HandleEventAsync(AccountingStandardChangeEvent eventData)
        {
            //无效的事件
            //if (!eventData.TenantId.HasValue || eventData.AccountingStandardType ==default)
            //    return;

            //using (_currentTenant.Change(eventData.TenantId))
            //{
            //    var count = await _accountRepository.GetCountAsync(new Querys.AccountQuery() { AccountingStandard= eventData.AccountingStandardType});

            //    //加载过了
            //    if (count > 0)
            //        return;

            //   var defaultAccounts = await _accountRepository.GetDefaultAccounts(eventData.AccountingStandardType);

            //   //await _


            //}
        }
    }
}
